package com.b2c.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

import com.b2c.entity.EticMarka;

public class EticMarkaDAO extends BaseDAO {

	public EticMarkaDAO(Session session) {
		super.session = session;
	}

	public EticMarka getMarkaById(long id) {
		Criteria criteria = session.createCriteria(EticMarka.class);
		criteria.add(Restrictions.eq("id", id));
		List<EticMarka> eticMarkas = criteria.list();

		if (eticMarkas != null && eticMarkas.size() > 0)
			return eticMarkas.get(0);
		return null;
	}

	public void markaEkle(EticMarka eticMarka) {
		session.save(eticMarka);
	}

	public void markaGuncelle(EticMarka eticMarka) {
		session.update(eticMarka);
	}

	public void markaEkle(String markaAd) {
		EticMarka eticMarka = new EticMarka();
		eticMarka.setAd(markaAd);
		session.save(eticMarka);
	}

	public List<EticMarka> getTumMarkalar() {
		Criteria criteria = session.createCriteria(EticMarka.class);
		return criteria.list();
	}

	public void markaSil(EticMarka eticMarka) {
		session.delete(eticMarka);
	}

}
